//1.引入progress进度条
import nProgress from 'nprogress';
import 'nprogress/nprogress.css';
import router from "./router";
import store from './store';
const whiteList = ['/404', '/login']
router.beforeEach((to, from, next) => {
  nProgress.start()
  if (store.getters.token) {//表示已经登陆

    if (!store.getters.userId) {
      store.dispatch("user/getUserInfo");
    }


    if (to.path === '/login') {//是登录页面  跳转到首页
      next('/')
      nProgress.done()
    } else {//其他页面直接放行
      next()
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
      nProgress.done()
    }
  }
})

router.afterEach(() => {
  nProgress.done()
})



// const whiteList = ['/404', '/login']
// const isLogin = !!store.getters.token;//获取登录状态
// router.beforeEach((to, from, next) => {
//   nProgress.start()
//   //白名单包含
//   if (whiteList.includes(to.path)) {

//   }
// })

// router.afterEach(() => {
//   nProgress.done()

// })